package com.fxu.framework.core.sql;

import cn.hutool.core.collection.CollUtil;
import com.baomidou.mybatisplus.annotation.TableField;
import lombok.Getter;
import lombok.Setter;

import java.io.Serializable;
import java.util.Collection;

/**
 * 基础实体类父类
 * 支持写法 SQuery sQuery = new Test().query(1);
 * @author fangxu
 * @version 1.0.0
 */
@Getter
@Setter
public abstract class SEntity<SE extends SEntity<?>> implements Serializable {
    private static final long serialVersionUID = 1L;

    /**
     * 表名字
     */
    @TableField(exist = false)
    private String table$;

    @SafeVarargs
    @SuppressWarnings({"varargs", "unchecked"})
    public final SQuery<SE> show(SFunc<SE, ?>... sFunctions) {
        return new SQuery<>((Class<SE>) this.getClass()).show(sFunctions);
    }

    @SuppressWarnings("unchecked")
    public SQuery<SE> query() {
        return new SQuery<>((Class<SE>) this.getClass());
    }

    @SuppressWarnings("unchecked")
    public SQuery<SE> query(Serializable id) {
        return new SQuery<SE>((Class<SE>)this.getClass()){}.ids(CollUtil.toList(id));
    }

    @SuppressWarnings("unchecked")
    public SQuery<SE> query(Collection<Serializable> ids) {
        return new SQuery<SE>((Class<SE>)this.getClass()){}.ids(ids);
    }

    @SuppressWarnings("unchecked")
    public SUpdate<SE> update() {
        return new SUpdate<SE>((Class<SE>) this.getClass()){};
    }

    @SuppressWarnings("unchecked")
    public SUpdate<SE> update(Serializable id) {
        return new SUpdate<SE>((Class<SE>) this.getClass()){}.id(id);
    }

}
